package com.fk.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.fk.entity.User;
import com.fk.uitl.DBManager;

public class UserDaoImpl {
	public int addMessage(User user) {
		return DBManager.executeUpdate("insert into user values('"+user.getUsername()+"','"+user.getPhone()+"','"+user.getEmail()+"','"+user.getContent()+"')");
	}
	public List<User> getLiuYan() {
		List<User> userList = new ArrayList<User>();
		Connection conn = DBManager.getConnection();
		Statement st = null;
		ResultSet rs = null;
		User user = null;
		try {
			st = conn.createStatement();
			rs = st.executeQuery("select * from user ");
			while(rs.next()) {
				String username = rs.getString("username");
				String phone  = rs.getString("phone");
				String email  = rs.getString("email");
				String content = rs.getString("content");
				 user = new User(username, phone, email, content);
				 userList.add(user);
			}
			return userList;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
	}
}
